#pragma once
#include "stdafx.h"
#include "common.h"
#include "scene.h"
#include "units.h"
//#include "indicator.h"
#include "automatic_item.h"

class Common;
class SceneView;
class QGraphicsSceneMouseEvent;
class automaticItem;
class autConPoint;

class FlowTracker : public QObject
{
	Q_OBJECT
public:
	const enum state_t{ ANALYSIS, WORK, PAUSE, FAILURE };
	FlowTracker(Common* _common, SceneView* _scene, automaticItem* _parent, const bool display_title);
	FlowTracker::~FlowTracker();
	void init_model();
	//QString getName();
	//QString getParentName(){ return parent->getName(); }
	automaticItem * getParent(){ return parent; }
	void popupShow(QGraphicsSceneContextMenuEvent *event);
private:

	Common* common;
	SceneView* scene;
	automaticItem* parent;
	vector<autConPoint> *list_of_conPoint;
	state_t state;
	double calc_delta_average_pressure(const vector<double> &left_sensor, const vector<double> &right_sensor);
	int calc_set_point(const double &time, const double &mismatch_between_A_and_Qr, const double &delta_average_pressure, 
		const double &min_set_point, vector<pair<QVector<double>, QVector<double>>> &data);
	double calc_Qr();
	double calc_mismatch_between_A_and_Qr(const double &A, const double &Qr);
	FlowTracker::state_t calc_state(const double &time, const double &delta_average_pressure, const double &mismatchAandB, const bool &isFailture);
	//double calc_state
	//static QVector<double> create_table_DP();
private slots:
	void removeScriptParameter(const QString &script_name);
	void addScriptParameter(const QString &script_name);
	void addLayer(const double &time, const double & dt );
protected:
	void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
	void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
signals:

};
